<?php
namespace app\index\controller;

class Detail extends Base
{
    public function index()
    {
        $id = input('id',0,'intval');
        if(!$id){
            $this->error('ID不合法');
        }
        //根据id查询商品的数据
        $deal = model('Deal')->get($id);
        if(!$deal || $deal->status !=1){
            $this->error('该商品不存在');
        }
        //获取分类信息
        $category = model('category')->get($deal->category_id);
        //获取分店信息y
        $locations = model('BisLocation')->getLocationInId($deal->location_ids);

        $flag = 0;
        $tip = '团购活动正在进行中...';
        if($deal->start_time > time()){
            $flag = 1;
            $dtime = $deal->start_time - time();
            $d = floor($dtime/(3600*24));
            $h = floor(($dtime%(3600*24)/3600));
            $m = floor(($dtime%(3600*24)%3600/60));
            $s = floor(($dtime%(3600*24)%3600%60));
            $tip = $d.'天 '.$h.'小时 '.$m.'分 '.$s.'秒';
        }
        return $this->fetch('',[
            'deal' => $deal,
            'title' => $deal->name,
            'category' =>$category,
            'locations' => $locations,
            'flag' => $flag,
            'tip' => $tip,
            'center' => $locations[0]['xpoint'].','.$locations[0]['ypoint'],
            ]);
    }
}